<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>角色权限·</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, shrink-to-fit=no"/>
    <meta name="renderer" content="webkit"/>
    <meta name="force-rendering" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <link rel="stylesheet" href="/static/admin/static/component/pear/css/pear.css"/>
    <link href="/static/public/libs/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link href="/static/admin/static/css/main.css" rel="stylesheet"/>
</head>
<body>
<div id="test1"></div>
<script src="/static/public/libs/jquery/jquery-3.5.1.min.js"></script>
<script src="/static/public/libs/layui-v2.5.6/layui/layui.js"></script>
<script src="/static/admin/static/component/pear/pear.js"></script>
<script>
    let form, element, layer;
    layui.use(['layer', 'form', 'element', 'tree'], function () {
        var frist = true;
        form = layui.form;
        element = layui.element;
        layer = layui.layer;
        var dtree = layui.tree;
        dtree.render({
            elem: "#test1"
            ,data:#(data)
            ,showCheckbox: true  //是否显示复选框
            ,oncheck: function(obj){
                if (!frist) {
                    var requestData = {roleId: #(role.id), permissionId: obj.data.value};
                    $.ajax({
                        type: "POST",
                        url: "/admin/role/updatePermissionByRoleId/" + obj.checked,
                        contentType: "application/json",
                        data: JSON.stringify(requestData),
                        success: function (data) {
                            if (data.code === 200) {
                                layer.msg(data.msg);
                            } else {
                                layer.msg(data.msg, {icon: 2});
                            }
                        }
                    });
                }
                frist = false;
            }
        });
    });
</script>
</body>
</html>
